﻿// cmdAddLineCurveCommand.cpp
//

#include "stdafx.h"


////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// BEGIN AddLineCurveCommand command
//

#pragma region AddLineCurveCommand command

class CCommandAddLineCurveCommand : public CRhinoCommand
{
public:
	CCommandAddLineCurveCommand() = default;
	UUID CommandUUID() override
	{
		// {7fd06f16-6d51-4111-a4cb-ce82b516d57c}
		static const GUID AddLineCurveCommandCommand_UUID =
		{0x7fd06f16,0x6d51,0x4111,{0xa4,0xcb,0xce,0x82,0xb5,0x16,0xd5,0x7c}};
		return AddLineCurveCommandCommand_UUID;
	}
	const wchar_t* EnglishCommandName() override { return L"AddLineCurve"; }
	CRhinoCommand::result RunCommand(const CRhinoCommandContext& context) override;
};

// The one and only CCommandAddLineCurveCommand object
static class CCommandAddLineCurveCommand theAddLineCurveCommandCommand;

CRhinoCommand::result CCommandAddLineCurveCommand::RunCommand(const CRhinoCommandContext& context)
{
	CRhinoGetPoint gp;
	gp.SetCommandPrompt(L"Start of line");
	gp.GetPoint();
	if (gp.CommandResult() != CRhinoCommand::success)
		return gp.CommandResult();

	ON_3dPoint pt_start = gp.Point();

	gp.SetCommandPrompt(L"End of line");
	gp.SetBasePoint(pt_start);
	gp.DrawLineFromPoint(pt_start, TRUE);
	gp.GetPoint();
	if (gp.CommandResult() != CRhinoCommand::success)
		return gp.CommandResult();

	ON_3dPoint pt_end = gp.Point();
	ON_3dVector v = pt_end - pt_start;
	if (v.IsTiny())
		return CRhinoCommand::nothing;

	ON_Line line(pt_start, pt_end);

	context.m_doc.AddCurveObject(line);
	context.m_doc.Redraw();

	return CRhinoCommand::success;
}

#pragma endregion

//
// END AddLineCurveCommand command
//
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
